<template>
    <div>
        <!-- 发布报道板块 -->
        <div>
            <el-form :model="report">
                <el-form-item label="学院信息" :label-width="formLabelWidth">
                    <el-select v-model="report.collegeId" placeholder="请选择学院">
                        <el-option v-for="item in collegeList" :label="item.name" :value="item.id" :key="item.id"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="报道标题" :label-width="formLabelWidth">
                    <el-input v-model="report.title" placeholder="请输入标题" />
                </el-form-item>
                <el-form-item label="报道内容" :label-width="formLabelWidth">
                    <textarea v-model="report.content" style="width:100%"></textarea>
                </el-form-item>
                <el-form-item label="" :label-width="formLabelWidth">
                    <el-button type="primary" size="mini" @click="add">发布</el-button>
                </el-form-item>
            </el-form>
        </div>
    </div>
</template>
<script>
export default {
    data() {
        return {
            reportList: [],
            collegeList: [],
            report: {
                collegeId: '',
                title: '',
                content: ''
            }
        };
    },
    methods: {
        async allReport() {
            const res = await this.getJSON(`/report/findlist`);
            this.reportList = res.data.reocrds;
        },
        async add() {
            if(this.report.collegeId==null || this.report.collegeId==''){
                this.$message.error('必须选择学院')
                return false
            }
            if(this.report.title==null || this.report.title==''){
                this.$message.error('标题不能为空')
                return false
            }
            if(this.report.content==null || this.report.content==''){
                this.$message.error('内容不能为空')
                return false
            }
            const res = await this.postJSON(`/report/addreport`,this.report);
            console.log(res);
            if (res.code == 200) {
                this.$message.success('新增完成');
                this.allReport();
            }else{
                this.$message.error(res.msg);
            }
        },
        async allCollege() {
            const res = await this.getJSON(`/college/findall`);
            console.log(res);
            this.collegeList = res.data.records;
        }
    },
    created() {
        // 初始化加载数据
        this.allReport();
        this.allCollege();
    }
};
</script>
<style scoped></style>
